<link rel="stylesheet" href="../public/js/vendor/laydate/need/laydate.css">
<link rel="stylesheet" href="../public/js/vendor/laydate/skins/default/laydate.css">
<script src="../public/js/vendor/laydate/laydate.js"></script>
<link rel="stylesheet" href="../public/js/vendor/uploadify/mydemo/uploadify-demo.css">
<script src="../public/js/vendor/uploadify/jquery.uploadify.min.js"></script>
<script src="../public/js/vendor/kindeditor/kindeditor-all-min.js"></script>
<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i> 新闻详情</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-horizontal" role="form" method="post" action="" data-validate="validate">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">标题</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="" name="title" value="" disabled>
                                            </div>
                                            <!--<p class="col-sm-6 help-block">必填</p>-->
                                        </div>
                                        <hr/>


                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">发布时间:</label>
                                            <div class="col-sm-4">
                                                    <input type="text" class="form-control" id="publishTime" value=""/>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">内容</label>
                                            <div class="col-sm-10">
                                                <textarea class="form-control" id="editor" name="content"></textarea>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <div class=" col-sm-12">
                                                <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
                                            </div>
                                        </div>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>



<script>
    function validate($from) {
//        var title = $from.find('input[name="title"]');
//        if ($.trim(title.val()) == '') {
//            return '新闻标题不能为空';
//        }
        return true;
    }

    laydate({
        elem: '#publishTime',
        format: 'YYYY/MM/DD hh:mm:ss',
        istime: true,
        choose: function (datas) {
            console.log(datas);
        }
    });

    $(document).ready(function () {

        $("form").attr("action", common_conf.requestUrl+'news/edit');
//       getSupplyDetail($("#editid").val());
        initKindEditor("editor");
        getNewsyDetail($.getUrlVar('id'));

//        initPicUploadComponet();
    });

    function getNewsyDetail(id) {
        $.ajax({
            type: 'post',
            url: common_conf.requestUrl+'news/detail',
            contentType : 'application/json;charset=UTF-8',
            cache: false,
            data: '{"id":'+id+'}',
            dataType: 'json',
            beforeSend: function () {
            },
            success: function (returnData) {
                if(forceLogin(returnData)) return;
                var obj=returnData;
                if(obj.state=="success"){
                    initFormData(obj.data);
                }else{
                    alert("获取失败");
                }
            },
            error: function () {
                alert("未找到模板");
            }
        });
    }

    function initFormData($news) {
        $("input[name='title']").val($news.title);
        $("#publishTime").val($news.publishTime);
        editor.html($news.content);
        editor.sync();
        $('form').append("<input type='hidden' name='id' value='"+$news.id+"'>");
    }
</script>
